package org.programmers.anonymous.fightrobots.model;

import org.apache.commons.lang.builder.HashCodeBuilder;


public class Weapon implements IWeapon, Comparable<Weapon>, Cloneable
{
	protected int idWeapon;
	protected String name;
	protected int power;
	protected int hits;

	public Weapon(){
		this.setIdWeapon(-99);
		this.setName("Iron Fist");
		this.setPower(20);
		this.setHits(10);
	}
	
	@Override
	public int getIdWeapon() {
		return this.idWeapon;
	}

	@Override
	public void setIdWeapon(int idW) {
		this.idWeapon = idW;
	}
	
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String n) {
		name = n;
	}

	@Override
	public int getPower() {
		return power;
	}

	@Override
	public void setPower(int p) {
		power = p;
	}
	
	@Override
	public int getHits() {
		return hits;
	}

	@Override
	public void setHits(int hits) {
		this.hits = hits;
	}

	@Override
	public int compareTo(Weapon w) {
		if (this.getName().compareTo(w.getName()) == 0 && this.getPower() == w.getPower())
		{
			return 0;
		}	
		else 
		{
			return this.getName().compareTo(w.getName());
		}
	}
	
	@Override
	public Weapon clone()
	{
		Weapon result = new Weapon();
		result.setName(new String(this.getName()));
		result.setPower(this.getPower());
		return result;
	}
	
	@Override
	public boolean equals(Object obj)
	{
		if (obj == null)
            return false;
        if (obj == this)
            return true;
        if (!(obj instanceof IWeapon))
            return false;

		IWeapon w = (IWeapon) obj;
		
		if(this.getName().equalsIgnoreCase(w.getName()))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	@Override
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("{");
		strBuff.append("idWeapon:");
		strBuff.append(idWeapon);
		strBuff.append(",name:");
		strBuff.append(name);
		strBuff.append(",power:");
		strBuff.append(power);
		strBuff.append(",hits:");
		strBuff.append(hits);
		strBuff.append("}");
		
		return strBuff.toString();
	}
	
	@Override
	 public int hashCode() {
	        return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
	            // if deriving: appendSuper(super.hashCode()).
	            append(name).
	            toHashCode();
	}
		
}
